#include "../../framework/framework.h"
#include "../inc/xShader.h"
#include "../inc/xDevice.h"
#include "../inc/xMedia.h"
namespace Sky
{

	TUint xEffect::ms_Flags = 0;

	TResult xEffect::onCreate( xDxApp* app )
	{
		return XE_OK;
	}

	TResult xEffect::onCreate( xDevice* device )
	{
		TResult hr = XE_APICALL;
		TChar fullName[512] = {0};
		switch(m_Type)
		{
		case From_Create:
			//hr = D3DXCreateEffect(device->getDevice9())
			break;
		case From_File:
			myDeV_Ret_hr_M(xMedia::FindMediaFile(xMedia::eType_fx,m_srcFile->toCharString(),fullName,sizeof(fullName)),XE_APICALL);
			hr = D3DXCreateEffectFromFile(device->getDevice9(),fullName,vNull,vNull,m_Flags,vNull,&m_Res,vNull);
			break;
		case From_Ex | From_File:
			break;
		} // switch(m_Type)
		if(FAILED(hr)){
			myDx_Trace_hr1(M,hr,_XT("xEffect::onCreate() with type(%d) failed"),m_Type);
			return XE_APICALL;
		}
		return XE_OK;
	}
	TResult xEffect::onDelete( xDxApp* app )
	{
		Finalise();
		return XE_OK;
	}

	TResult xEffect::onDelete( xDevice* device )
	{
		SAFE_RELEASE(m_Res);
		return XE_OK;
	}
	TResult xEffect::onReset( xDevice* device )
	{
		myDxV_Ret_hr_M(m_Res->OnResetDevice(),XE_APICALL);
		return XE_OK;
	}

	TResult xEffect::onLost( xDevice* device )
	{
		myDxV_Ret_hr_M(m_Res->OnLostDevice(),XE_APICALL);
		return XE_OK;
	}

	TVoid xEffect::Initialise()
	{
		m_Type = From_Create;
		m_Flags = 0;
		return;
	}

	xEffect::xEffect()
	{
		Initialise();
	}

	xEffect::~xEffect()
	{
		Finalise();
	}

	TVoid xEffect::Finalise()
	{
		SAFE_RELEASE(m_Res);
	}
}